import { state } from '@angular/animations';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
@Injectable({
  providedIn: 'root'
})
export class SupplierPriceService {
   data = '/Supply'
  constructor(private http: HttpClient) { }
  getSupplierPrice(filter:{
    PageSize:number,
    PageNumber:number,
    SearchTerm:string,
    SupplyId:number,
    SearchStatus:string,
  }){
    Object.keys(filter).forEach(key => filter[key] === null ? delete filter[key] : {});
    return this.http.get(environment.apiUrl + this.data+ '/GetPurchasePriceScheduleWithSub', {params:filter})
  }
  addSupplierPrice(data:any){
    return this.http.post(environment.apiUrl + this.data + '/CreatePurchasePriceSchedule', data)
  }
  getSupplierPriceById(id:any){
    return this.http.get(environment.apiUrl + this.data + '/GetPurchasePriceScheduleById', {params:{
      purchasePriceScheduleId:id
    }})
  }
  editSupplierPrice(id:any, data:any){
    return this.http.put(environment.apiUrl + this.data + '/UpdatePurchasePriceSchedule', data, {params:{
      purchasePriceScheduleId:id
    }})
  }
  auditSupplierPrice(state:any,ids:any){
    return this.http.put(environment.apiUrl + this.data + '/ChangePurchasePriceSchedule', ids, {params:{
      status:state
    }}
    )
  }
  deleteSupplierPrice(ids:any){
    const options = {
      body: ids,
      responseType: 'text' as 'json'
    };
    return this.http.delete(environment.apiUrl + this.data + '/DeleteBatchPurchasePriceSchedule', options)
  }
  downloadExcel(){
    return this.http.get(environment.apiUrl + '/Excel/DownloadPurchasePriceScheduleFileModel', {responseType: 'blob'})
  }
  uploadExcel(){
    return this.http.get(environment.apiUrl + '/Excel/DownloadPurchasePriceScheduleFile', {responseType: 'blob'})
  }
  importExcel(file:File){
    const formData: FormData = new FormData();
    formData.append('file', file, file.name);
    return this.http.post(environment.apiUrl + '/Excel/ImportPurchasePriceScheduleFromExcel', formData,{ responseType: 'blob'
    })
  }
  getVaildPriceByPartId(partIds:any){
    return this.http.get(environment.apiUrl + this.data + '/GetVaildPriceByPartId', {params:{
      partIds:partIds
    }})
  }
}
